内存锁模块,也称之为 动态互斥锁
模块,支持按照 给定键名动态生成互斥锁
,并发安全并支持 Try*Lock
特性。
当维护大量动态互斥锁的场景时,如果不再使用的互斥锁对象,请手动调用
Remove
方法删除掉。
使用方式:
import "github.com/gogf/gf/os/gmlock"
使用场景: 需要 动态创建互斥锁
,或者需要 维护大量动态锁
的场景;
接口文档:
https://godoc.org/github.com/gogf/gf/os/gmlock
func Lock(key string)
func LockFunc(key string, f func())
func RLock(key string)
func RLockFunc(key string, f func())
func RUnlock(key string)
func Remove(key string)
func TryLock(key string) bool
func TryLockFunc(key string, f func()) bool
func TryRLock(key string) bool
func TryRLockFunc(key string, f func()) bool
func Unlock(key string)
type Locker
func New() *Locker
func (l *Locker) Clear()
func (l *Locker) Lock(key string)
func (l *Locker) LockFunc(key string, f func())
func (l *Locker) RLock(key string)
func (l *Locker) RLockFunc(key string, f func())
func (l *Locker) RUnlock(key string)
func (l *Locker) Remove(key string)
func (l *Locker) TryLock(key string) bool
func (l *Locker) TryLockFunc(key string, f func()) bool
func (l *Locker) TryRLock(key string) bool
func (l *Locker) TryRLockFunc(key string, f func()) bool
func (l *Locker) Unlock(key string)